package com.baseweb.webadmin.core.model.mapper;

import com.baseweb.webadmin.core.model.Sql.SqlProvider;
import com.baseweb.webadmin.core.model.pojo.ByExampleDiscuss;
import com.baseweb.webadmin.core.util.RequestPage;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by zx on 2017/8/2.
 */
public interface ByExampleDiscussMapper {
    @Delete({
            "delete from by_example_discuss",
            "where id = #{id,jdbcType=INTEGER}"
    })
    Integer deleteByPrimaryKey(Integer id);

    @Select({
            "select",
            "id, example_id, name, imgUrl, content, score, create_time, ",
            "update_time",
            "from by_example_discuss",
            "where id = #{id,jdbcType=INTEGER}"
    })
    @ResultMap("BaseResultMap")
    ByExampleDiscuss selectByPrimaryKey(Integer id);

    @Insert({
            "insert into by_example_discuss (example_id, name,score, imgUrl, content,  create_time, ",
            "update_time)",
            "values (#{exampleId,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR},#{score,jdbcType=INTEGER}, ",
            "#{imgUrl,jdbcType=VARCHAR},#{content,jdbcType=VARCHAR},  ",
            " #{createTime,jdbcType=TIMESTAMP,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2TimestampTypeHandler}, ",
            "#{updateTime,jdbcType=TIMESTAMP,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2TimestampTypeHandler})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Integer.class)
    Integer insert(ByExampleDiscuss record);

    @Update({
            "update by_example_discuss",
            "set score = #{score,jdbcType=INTEGER},",
            "name = #{name,jdbcType=VARCHAR},",
            "imgUrl = #{imgUrl,jdbcType=VARCHAR},",
            "content = #{content,jdbcType=VARCHAR},",
            "create_time = #{createTime,jdbcType=TIMESTAMP,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2TimestampTypeHandler},",
            "update_time = #{updateTime,jdbcType=TIMESTAMP,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2TimestampTypeHandler}",
            "where id = #{id,jdbcType=INTEGER}"
    })
    Integer updateByPrimaryKey(ByExampleDiscuss record);

    @SelectProvider(type = SqlProvider.class,method = "selectExampleDiscussListByPage")
    @ResultMap("BaseResultMap")
    List<ByExampleDiscuss> selectExampleDiscussListByPage(@Param("exampleId")Integer exampleId, @Param("page")RequestPage page);

    @SelectProvider(type = SqlProvider.class,method = "countExampleDiscussListByPage")
    Integer countExampleDiscussListByPage(@Param("exampleId")Integer exampleId, @Param("page")RequestPage page);
}
